<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML5 获取位置信息</title>
    <script>
        const getLocation = () => {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(
                    (position) => {
                        console.log('定位时间：', position.timestamp)
                        console.log('经度：', position.coords.longitude)
                        console.log('纬度：', position.coords.latitude)
                        console.log('海拔：', position.coords.altitude)
                        console.log('速度：', position.coords.speed)
                    },
                    (error) => {
                        switch (error.code) {
                            case error.PERMISSION_DENIED:
                                console.log('用户拒绝对获取地理位置的请求。');
                                break;
                            case error.POSITION_UNAVAILABLE:
                                console.log('位置信息是不可用的。');
                                break;
                            case error.TIMEOUT:
                                console.log('请求用户地理位置超时。');
                                break;
                            case error.UNKNOWN_ERROR:
                                console.log('未知错误。');
                                break;
                        }
                    }
                );
            }
            else {
                console.log('该浏览器不支持获取地理位置。');
            }
        }
        getLocation();
    </script>
</head>

<body>

</body>

</html>